#include "demo.h"

void main() {
	const char * test, * uncompressed;
	rwig_str compressed;

	rwig_init();

	test = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
	compressed = compress(test);

	if(!compressed.buf) {
		printf("Error compressing string.\n");
		PyErr_Print();
		exit(-1);
	}

	printf("Achieved %.1f%% compression using py_zlib.\n", strlen(test)/(double)compressed.len*100);

	uncompressed = uncompress(compressed);

	if(!uncompressed) {
		printf("Error decompressing string.\n");
		PyErr_Print();
		exit(-1);
	}

	if(strcmp(uncompressed, test) == 0)
		printf("Test string uncompressed successfully.\n");
	else
		printf("Test string not uncompressed successfully.\n");

	/* When a python function returns a c string, you have to free it afterwards
	In C++ you would preferably use a smart pointer. */
	rwig_free(&compressed);
	free(uncompressed);

	rwig_finalize();
}